package com.zja.service.Impl;

import com.zja.dao.ArticleDao;
import com.zja.dao.Impl.ArticleDaoImpl;
import com.zja.model.Article;
import com.zja.service.ArticleService;

import java.util.List;

/**
 * @author JA
 * @date: 2025/5/4
 * description:
 */
public class ArticleServiceImpl implements ArticleService {
    private final ArticleDao articleDao = new ArticleDaoImpl();

    @Override
    public List<Article> getAllArticles() {
        return articleDao.selectAll();
    }

    @Override
    public Article getArticleById(Long id) {
        return articleDao.selectById(id);
    }

    @Override
    public boolean createArticle(Article article) {
        return articleDao.insert(article);
    }

    @Override
    public boolean updateArticle(Article article) {
        return articleDao.update(article);
    }

    @Override
    public boolean deleteArticle(Long id) {
        return articleDao.deleteById(id);
    }

    @Override
    public List<Article> getArticlesByKnowledgeBaseId(Long kbId) {
        return articleDao.selectByKnowledgeBaseId(kbId);
    }

    @Override
    public List<Article> searchArticles(Long kbId, String keyword, int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return articleDao.searchArticles(kbId, keyword, offset, pageSize);
    }

    @Override
    public int countArticles(Long kbId, String keyword) {
        return articleDao.countArticles(kbId, keyword);
    }

}
